home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------
- // KeyholeBitmap.cs ⌐ 2001 by Charles Petzold
- //--------------------------------------------
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Windows.Forms;
-
- class KeyholeBitmap: PrintableForm
- {
- Bitmap bitmap;
-
- public new static void Main()
- {
- Application.Run(new KeyholeBitmap());
- }
- public KeyholeBitmap()
- {
- Text = "Mapa de bits con el ojo de la cerradura";
-
- // Cargar imagen.
-
- Image image = Image.FromFile(
- "..\\..\\..\\..\\Images and Bitmaps\\Apollo11FullColor.jpg");
-
- // Crear trazado de recorte.
-
- GraphicsPath path = new GraphicsPath();
- path.AddArc(80, 0, 80, 80, 45, -270);
- path.AddLine(70, 180, 170, 180);
-
- // Obtener el tama±o del trazado de recorte.
-
- RectangleF rectf = path.GetBounds();
-
- // Crear mapa de bits nuevo inicializado a transparente.
-
- bitmap = new Bitmap((int) rectf.Width, (int) rectf.Height,
- PixelFormat.Format32bppArgb);
-
- // Crear objeto Graphics basado en el nuevo mapa de bits.
-
- Graphics grfx = Graphics.FromImage(bitmap);
-
- // Dibujar la imagen original en el mapa de bits con recorte.
-
- grfx.SetClip(path);
- grfx.TranslateClip(-rectf.X, -rectf.Y);
- grfx.DrawImage(image, (int) -rectf.X, (int) -rectf.Y,
- image.Width, image.Height);
- grfx.Dispose();
- }
- protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
- {
- grfx.DrawImage(bitmap, (cx - bitmap.Width) / 2,
- (cy - bitmap.Height) / 2,
- bitmap.Width, bitmap.Height);
- }
- }
-